"use strict";

module.exports = (app) => {
  const { STRING, INTEGER, DATE } = app.Sequelize;

  const User = app.model.define(
    "syuser",
    {
      userid: { type: INTEGER, primaryKey: true, autoIncrement: true },
      username: STRING(30),
      userpwd: STRING(32),
      avatar: STRING(150),
      created_at: {
        type: DATE,
        get() {
          return app.formatTime(this.getDataValue("created_at"));
        },
      },
      updated_at: {
        type: DATE,
        get() {
          return app.formatTime(this.getDataValue("updated_at"));
        },
      },
      Co_ID: INTEGER,
      scope: INTEGER,
    },
    {
      tableName: "sy_user",
      timestamps: false,
      underscored: false,
    }
  );

  User.associate = function() {
    app.model.Syuser.belongsTo(app.model.TCompanycnfo, { as: 'company', foreignKey: 'Co_ID' });
  };

  return User;
};
